<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <el-form :inline="true" :model="ruleForm" ref="ruleForm" status-icon :rules="rules">
        <el-form-item label="用户名" prop="username">
            <el-input  v-model="ruleForm.username" placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input type="password" v-model="ruleForm.password" placeholder="密码"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">查询</el-button>
        </el-form-item>
    </el-form>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
    new Vue({
        el: '#app',
        data: function () {
            var validateUser = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请输入用户名'));
                }
                    callback();
            };
            var validatePass = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请输入密码'));
                }
                    callback();
            };
            return {
                ruleForm: {
                    username: '',
                    password: ''
                },
                rules:{
                    username:[{required: true,validator: validateUser,trigger: 'blur' }],
                    password:[{required: true,validator: validatePass,trigger: 'blur' }]
                }
            }
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        this.$ajax.get('api/uaa/oauth/token',{
                            params:{username:'user_1',password:'123456'}
                        })
                            .then((response) => {
                                this.$message.success('注册成功！')
                            });
                    } else {
                        return false;
                    }
                });
            }
        }
    })
</script>
</html>